package cn.wolfcode.crm.service.impl;

import cn.wolfcode.crm.domain.Personnel;
import cn.wolfcode.crm.mapper.PersonnelMapper;
import cn.wolfcode.crm.query.PersonnelQueryObject;
import cn.wolfcode.crm.service.IPersonnelService;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PersonnelServiceImpl implements IPersonnelService {

    @Autowired
    private PersonnelMapper mapper;


    public void save(Personnel personnel) {
        mapper.insert(personnel);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(Personnel personnel) {
        mapper.updateByPrimaryKey(personnel);
    }

    public Personnel get(Long id) {
        Personnel personnel = mapper.selectByPrimaryKey(id);
        return personnel;
    }

    public List<Personnel> listAll() {
        List<Personnel> list = mapper.selectAll();
        return list;
    }

    public PageResult query (PersonnelQueryObject qo) {
        //1:查总条数
        int total = mapper.queryForCount(qo);
        System.out.println(qo);

        if(total == 0){
            return new PageResult();
        }
        //2:查分页数据
        List<Personnel> rows = mapper.queryForList(qo);

        return new PageResult(total, rows);
    }
}
